home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / mouser.zip / MOUSER.PAS < prev   
Pascal/Delphi Source File  |  1993-01-04  |  5KB  |  130 lines

  1. Unit Mouser;
  2.  
  3.  
  4. {*****************************************************************************}
  5. {                                                                             }
  6. {    The Mouse Unit contains mouse routines to interface with different       }
  7. {    programs.  It was written by Charles Hahn.                               }
  8. {                                                                             }
  9. {*****************************************************************************}
  10.  
  11.  
  12.    interface
  13.  
  14.       uses
  15.          dos,
  16.          crt;
  17.  
  18.       type
  19.          mousemove = record
  20.             xmouse : integer;
  21.             ymouse : integer;
  22.          end;
  23.  
  24.  
  25.       var
  26.          mousepresent : boolean;
  27.          leftbutton   : boolean;
  28.          rightbutton  : boolean;
  29.          centerbutton : boolean;
  30.          numberbutton : integer;
  31.          lastmouse    : mousemove;
  32.  
  33.       function mouseready : boolean;
  34.  
  35.           {This function returns whether the mouse and driver are present. }
  36.           {It was written by Charles Hahn.                                 }
  37.  
  38.       function mousebuttonpressed : boolean;
  39.  
  40.           {This function checks to see if a button has been pressed on the }
  41.           {mouse.  If a button has been pressed, the function will then set}
  42.           {the correct boolean variable. It was written by Charles Hahn.   }
  43.  
  44.       function questionmouse : boolean;
  45.  
  46.           {This function checks to see if the mouse has any information to }
  47.           {pass to the calling program.  It works like the KEYPRESSED      }
  48.           {function in TP.  It was written by Charles Hahn                 }
  49.  
  50.       procedure mousemoved(var movement : mousemove);
  51.  
  52.           {This procedure reads the mouses movement counters and returns   }
  53.           {the x-y movement information.  This information is not scaled in}
  54.           {any way and the numbers returned are actual mickeys.  It was    }
  55.           {written by Charles Hahn.                                        }
  56.  
  57.  
  58.    implementation
  59.  
  60.       function mouseready : boolean;
  61.  
  62.          var
  63.             regs : registers;
  64.          begin
  65.             regs.ax := $0000;  {AX = 0000H tests for presence of mouse and driver}
  66.             intr($33, regs);
  67.             if ((regs.AX and $FFFF) = $FFFF) then
  68.             begin
  69.                mousepresent := true;  {if AX = FFFFH then the mouse is present and}
  70.                numberbutton := regs.BX; {and BX contains the number of buttons}
  71.             end                         {on the mouse.}
  72.             else
  73.             begin
  74.                mousepresent := false;
  75.                numberbutton := 0;
  76.             end;
  77.             mouseready := mousepresent;
  78.          end;
  79.  
  80.       function mousebuttonpressed : boolean;
  81.          var
  82.             regs : registers;
  83.             temp : word;
  84.          begin
  85.             regs.AX := $0005; {0005H gets button pressed information}
  86.             regs.BX := $0007; {BX contains the identifier for the buttons to check}
  87.             intr($33, regs);
  88.             temp := (regs.AX and $0007);{the information is in the last 3 bits}
  89.             leftbutton := ((temp and $0001) = $0001); {This means the left button is pressed}
  90.             rightbutton := ((temp and $0002) = $0002); {This means the right button is pressed}
  91.             centerbutton := ((temp and $0004) = $0004); {This means the center button is pressed}
  92.             mousebuttonpressed := (leftbutton or rightbutton or centerbutton);
  93.                {The result is true if any button has been pressed}
  94.          end;
  95.  
  96.       function questionmouse : boolean;
  97.          var
  98.             regs : registers;
  99.          begin
  100.             regs.AX := $03; {Get mouse position and status}
  101.             intr($33, regs);
  102.             if (((regs.BX and $0007) > 0) or (lastmouse.xmouse <> regs.CX) or (lastmouse.ymouse <> regs.DX)) then
  103.             begin
  104.                lastmouse.xmouse := regs.CX;
  105.                lastmouse.ymouse := regs.DX;
  106.                questionmouse := true; {This returns true if a button has been pressed}
  107.             end                       {or the mouse has been moved}
  108.             else
  109.                questionmouse := false;
  110.          end;
  111.  
  112.       procedure mousemoved(var movement : mousemove);
  113.          var
  114.             check : mousemove;
  115.             regs  : registers;
  116.          begin
  117.             regs.AX := $000B; {Read mouse motion counters}
  118.             intr($33, regs);
  119.             if ((regs.CX and $8000) = $8000) then
  120.                check.xmouse := -(not(regs.CX)) {Since the registers are unsigned   }
  121.             else                               {integers this check for negative   }
  122.                check.xmouse := regs.CX;        {movement. Positive numbers are     }
  123.             if ((regs.DX and $8000) = $8000) then {DOWN and RIGHT, negative numbers}
  124.                check.ymouse := -(not(regs.DX))    {are UP and LEFT}
  125.             else
  126.                check.ymouse := regs.DX;
  127.             movement := check;
  128.          end;
  129.  
  130.    end.